<%@ page contentType="text/html;charset=UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="shiro" uri="http://shiro.apache.org/tags"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>
<%@ taglib prefix="tags" tagdir="/WEB-INF/tags"%>
<c:set var="ctx" value="${pageContext.request.contextPath}" />
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title>不可处理订单</title>
<script type="text/javascript">
	var filterParam = {};
	var datatable_content;
	$(function() {
		$("#queryForm").validate();

		//初始化日期选择框
		var now = new Date();
		var today = (now.getFullYear())
				+ "/"
				+ (now.getMonth() < 10 ? "0" + (now.getMonth() + 1) : now
						.getMonth() +1) + "/"
				+ (now.getDate() < 10 ? "0" + now.getDate() : now.getDate());
		$("#_dataRange").val(today + "-" + today);
		$("#_dataRange").daterangepicker({
			format : 'YYYY/MM/DD',
			dateLimit : {
				days : 31
			}
		});
		$("#alreadyMyCheckedAll").iCheck({
			checkboxClass : 'icheckbox_minimal'
		});
		$("#alreadyMyCheckedAll").on("ifChecked", function(event) {
			$("input[name='alreadyMyChecked'").iCheck('check');
		});
		$("#alreadyMyCheckedAll").on("ifUnchecked", function(event) {
			$("input[name='alreadyMyChecked'").iCheck('uncheck');
		});
		/* initTable(); */
	});
	function initTable() {
		datatable_content = $("#contentTable")
				.dataTable(
						{
							"bServerSide" : true,
							"bAutoWidth" : false,
							"sAjaxSource" : '${ctx}/v2_resetOrder/queryResetOrder',
							"fnServerData" : callback,
							"fnRowCallback" : rowCallBack,
							//"sScrollX":"120%",
							"bFilter" : false,
							"bSort" : false,
							"sZeroRecords" : "查询无记录！",
							"bProcessing" : true,
							"iDisplayLength" : 100,//单页显示的数据的条数
							"oLanguage" : {
								"sUrl" : '${ctx}/static/v2/js/plugins/datatables/cn.txt'
							},
							"aoColumns" : [
									{
										"mData" : null,
										"mRender" : function(data, display, row) {
											var str = "<input type=\"checkbox\" name=\"alreadyMyChecked\" id=\"check_already"+row.id+"\" value="+row.id+"  />";
											return str;
										}
									},
									{
										"mData" : null,
									},
									{
										"mData" : null,
										"mRender" : function(data, display, row) {
											<c:forEach items="${customerList}" var="customer">
											if ("${customer.customerCode}" == row.customerCode) {
												return "${customer.customerName}";
											}
											</c:forEach>
											return "";
										}
									},
									{
										"mData" : 'warehouseCode'
									},
									{
										"mData" : 'ordeno',
										"render" : function(obj) {
											return "<a href='${ctx}/orderMsg/v2_orderMsgDetail/"+obj+"' title='查看订单信息' target='_blank'>"
													+ obj + "</a>";
										}
									},
									{
										"mData" : 'shopna'
									},
									{
										"mData" : 'recena'
									},
									{
										"mData" : 'provna'
									},
									{
										"mData" : 'cacode'
									},
									{
										"mData" : 'dispatchFlag',
										"render" : function(obj) {
											return "1" == obj ? "是" : "否";
										}
									},
									{
										"mData" : 'crtime',
										"render" : function(obj) {
											var time = obj.time;
											var date = new Date(time);
											return date.Format("MM-dd hh:mm");
										}
									},
									{
										"mData" : 'lastRestOrderTime',
										"render" : function(obj) {
											if (obj == null) {
												return null;
											} else {
												var time = obj.time;
												var date = new Date(time);
												return date
														.Format("MM-dd hh:mm");
											}
										}
									},
									{
										"mData" : 'addres',
										"render" : function(obj, type, full) {
											var ret = "<a href='#ordersDetail' onclick='getAjaxOrders("
													+ full.id
													+ ")' class='btn btn-default btn-sm' role='button' data-toggle='modal' >订单详情</a>";
											return ret
													+ " <a href='#orderItemsDetail' onclick='getAjaxItems("
													+ full.id
													+ ")' class='btn btn-default btn-sm' role='button' data-toggle='modal' >商品详情</a>";
										}
									} ]
						});
	}
	function filter(item) {
		filterParam[item.name] = item;
	}
	function callback(sSource, aoData, fnCallback) {
		//查询参数
		var customerCode = $("#_customerCode").val();
		aoData.push({
			"name" : "customerCode",
			"value" : customerCode
		});

		var warehouseCode = $("#_warehouseCode").val();
		aoData.push({
			"name" : "warehouseCode",
			"value" : warehouseCode
		});

		var dataRange = $("#_dataRange").val();
		aoData.push({
			"name" : "dataRange",
			"value" : dataRange
		});

		var orderno = $("#_orderno").val();
		aoData.push({
			"name" : "orderno",
			"value" : orderno
		});

		var logistics = $("#_logistics").val();
		aoData.push({
			"name" : "cacode",
			"value" : logistics
		});

		$.ajax({
			"type" : "post",
			"contentType" : "application/json",
			"url" : sSource,
			"dataType" : "json",
			"data" : JSON.stringify(aoData),
			"success" : function(resp) {
				fnCallback(resp);
				$("#total_unhandle").html("(" + resp.iTotalRecords + ")");
			}
		});
	}
	/**
	 *创建了行的回调
	 *nRow为当前的tr
	 */
	function rowCallBack(nRow, aData, iDisplayIndex, iDisplayIndexFull) {
		var iDisplayStart = datatable_content.fnSettings()._iDisplayStart;
		$("td:eq(1)", nRow).html(iDisplayStart + iDisplayIndex + 1);
	}

	function load() {
		//日期：
		var dataRange = $("#_dataRange").val();
		if (dataRange.length == 0) {
			alert("请选择日期范围...");
			return;
		}
		var customerCode = $("#_customerCode").val();
		if (customerCode.length == 0) {
			alert("请选择商家...");
			return;
		}
		var warehouseCode = $("#_warehouseCode").val();
		if (warehouseCode.length == 0) {
			alert("请选择仓库...");
			return;
		}
		if (datatable_content) {
			datatable_content.fnDestroy();
		}
		initTable();
	}
	function getCheckedList() {
		var tempChecked = [];
		$("input[type='checkbox'][name='alreadyMyChecked']:checked").each(
				function(i) {
					tempChecked.push($(this).val());
				});
		return tempChecked;
	}
	//批量重接订单
	function batchReuse() {
		var customerCode = $("#_customerCode").val();
		if (customerCode.length == 0) {
			alert("请选择商家...");
			return;
		}
		var dataRange = $("#_dataRange").val();
		if (dataRange.length == 0) {
			alert("请选择日期范围...");
			return;
		}
		var warehouseCode = $("#_warehouseCode").val();
		if (warehouseCode.length == 0) {
			alert("请选择仓库...");
			return;
		}
		var ids = getCheckedList();
		var len = ids.length;
		if (len > 100) {
			jAlert("选中的数量大于100", "错误提示");
			return false;
		}
		if (len == 0) {
			jAlert("请选择记录!", "错误提示");
			return false;
		}
		if (confirm('是否批量重接订单！')) {
			showBg();
			$.ajax({
				type : 'post',
				url : '${ctx}/v2_resetOrder/batchReuse',
				data : 'customerCode=' + customerCode + '&warehouseCode='
						+ warehouseCode + '&ids=' + ids + '&dataRange='
						+ dataRange,
				dataType : 'json',
				timeout : 240000,
				success : function(data) {
					closeBg();
					if (data.status == "1") {
						datatable_content.fnDraw();
						alert(data.msg);
					} else {
						alert(data.msg);
					}
				},
				error : function() {
					closeBg();
					alert("服务器异常，请重试");
				},

			});
		}
	}
	//导出不可处理订单
	function exportExcel() {
		if ($("#_customerCode").val().length == 0) {
			alert("请选择商家...");
			return;
		}
		if ($("#_warehouseCode").val().length == 0) {
			alert("请选择仓库...");
			return;
		}
		$("#queryForm").attr("action", "${ctx}/v2/firstPage/exportExcel");
		$("#queryForm").submit();
	}
</script>
</head>

<body>
	<div id="fullbg"></div>
	<div id="dialog">
		<div>
			<img src="${ctx }/static/022.gif"></img>
		</div>
	</div>
	<section class="content">
	<div class="row">
		<div class="col-md-12">

			<!-- Primary box -->
			<div class="box box-solid box-primary">
				<div class="box-header">
					<i class="fa fa-search"></i>
					<h3 class="box-title">搜索栏</h3>
					<div class="box-tools pull-right">
						<button class="btn btn-primary btn-sm" data-widget="collapse">
							<i class="fa fa-minus"></i>
						</button>
					</div>
				</div>
				<div class="box-body">
					<form class="form-search" id="queryForm" method="post">
						<!-- 第一行 -->
						<div class="form-group row">

							<div class="col-sm-3">
								<div class="input-textgroup col-sm-12">
									<span class="input-group-text"> 商家： </span> <select
										data-placeholder="请选择..." class="form-control searchSelect"
										id="_customerCode" name="_customerCode"
										onchange="ajaxAreaGroup(this,'_warehouseCode')">
										<option value=""></option>
										<c:forEach items="${customerList}" var="customer">
											<option value="${customer.customerCode}"
												<c:if test="${customerCode eq customer.customerCode}">selected=selected</c:if>>${customer.customerName}</option>
										</c:forEach>
									</select>
								</div>
							</div>

							<div class="col-sm-3">
								<div class="input-textgroup col-sm-12">
									<span class="input-group-text"> 仓库： </span> <select
										class="form-control span3" id="_warehouseCode"
										name="_warehouseCode">
										<option value=""></option>
										<c:forEach items="${warehouseList}" var="warehouse">
											<option value="${warehouse.groupCode}">${warehouse.groupName}</option>
										</c:forEach>
									</select>
								</div>
							</div>

							<div class="col-sm-3">
								<div class="input-textgroup col-sm-12">
									<span class="input-group-text"> 订单编号： </span> <input
										type="text" class="form-control" id="_orderno" name="_orderno">
								</div>
							</div>

						</div>

						<!-- 第二行 -->
						<div class=" form-group row">

							<div class="col-sm-6">
								<div class="input-textgroup col-sm-12">
									<span class="input-group-text"> 日期范围： </span>

									<div class="input-group">
										<div class="input-group-addon">
											<i class="fa fa-calendar"></i>
										</div>
										<input type="text" class="form-control pull-right"
											id="_dataRange" name="_dataRange" value="${param._fromDate}" />
									</div>

								</div>
							</div>
							<div class="col-sm-3">
								<div class="input-textgroup col-sm-12">
									<span class="input-group-text"> 快递公司： </span> <select
										class="form-control span3" id="_logistics" name="_logistics">
										<option value=""></option>
										<c:forEach items="${logisticsList}" var="logistics">
											<option value="${logistics.companyCode}">${logistics.companyName}</option>
										</c:forEach>
									</select>
								</div>
							</div>

						</div>
						<!-- 第三行 -->
						<div class=" form-group row">
							<div class="col-sm-3">
								<button class="btn btn-primary" type="button" onclick="load();">搜索</button>
								<button class="btn btn-info" type="button"
									onclick="exportExcel();">导出不可处理订单</button>
							</div>
						</div>
					</form>
				</div>
			</div>
		</div>
	</div>


	<div class="form-group row">
		<div class="col-md-12">
			<div class="box box-solid box-primary">
				<div class="box-header">
					<i class="fa fa-list"></i>
					<h3 class="box-title">查询结果</h3>
					<div class="box-tools pull-right">
						<button class="btn btn-primary btn-sm" data-widget="collapse"
							type="button">
							<i class="fa fa-minus"></i>
						</button>
					</div>
				</div>
				<div class="box-body">


					<table id="contentTable"
						class="table table-striped table-bordered table-condensed">
						<thead>
							<button class="btn btn-primary" type="button"
								onclick="batchReuse();">批量重接订单</button>
							<tr>
								<th style="width: 30px;"><input type="checkbox"
									name="alreadyMyCheckedAll" id="alreadyMyCheckedAll"
									onclick="alreadyMyCheckedAll()" /></th>
								<th style="width: 60px;">序号</th>
								<th style="width: 60px;">商家</th>
								<th style="width: 20px;">仓库</th>
								<th style="width: 100px;">能容订单号</th>
								<th style="width: 80px;">来源店铺</th>
								<th style="width: 50px;">收货人</th>
								<th style="width: 50px;">目的地</th>
								<th style="width: 50px;">快递公司</th>
								<th style="width: 30px;">可处理</th>
								<th style="width: 60px;">审单时间</th>
								<th style="width: 60px;">最后处理时间</th>
								<th style="width: 100px;">查询操作</th>
							</tr>
						</thead>
						<tbody>
						</tbody>
					</table>
				</div>
			</div>
		</div>
	</div>

	<!-- 弹出窗体-商品详情 start  -->
	<div id="ordersDetail" class="modal fade">
		<div class="modal-dialog" style="width: 60%;">
			<div class="modal-content">

				<div class="modal-body">
					<div class="box box-solid box-primary">
						<div class="box-header">
							<span class="box-title">订单详细信息</span>
						</div>
						<div class="box-body">
							<table class="table table-striped table-bordered table-condensed"
								id="modalBodyOrders"></table>
						</div>
					</div>
				</div>

			</div>
		</div>
	</div>
	<!-- 弹出窗体-商品详情 end  --> <!-- 弹出窗体-订单详情 start  -->
	<div id="orderItemsDetail" class="modal fade">
		<div class="modal-dialog" style="width: 60%;">
			<div class="modal-content">

				<div class="modal-body">
					<div class="box box-solid box-primary">
						<div class="box-header">
							<span class="box-title">订单详细信息</span>
						</div>
						<div class="box-body">
							<table class="table table-striped table-bordered table-condensed"
								id="modalBodyItems"></table>
						</div>
					</div>
				</div>

			</div>
		</div>
	</div>
	<!-- 弹出窗体-订单详情 end  --> </section>
</body>
</html>
